
#include "thread.h"
#include <sstream>

namespace ProcessRouter {

Thread::Thread()
    : m_running(false)
    , m_stop(true)
{
}

Thread::~Thread()
{
}

void Thread::start()
{
    m_stop = false;
    m_running = true;
    boost::function0< void> func = boost::bind(&Thread::run ,this);
    boost::thread thrd(func);
    thrd.detach();
}

void Thread::stop()
{
    m_stop = true;
}

void Thread::run()
{
    m_pid = getpid();

    std::stringstream stream;
    stream << boost::this_thread::get_id();
    m_tid = stream.str();

    std::cout << "Process : "<< m_pid << " Thread : " << m_tid << std::endl;
    threadMain();
    m_running = false;
}

std::string Thread::tid()
{
    return m_tid;
}

int Thread::pid()
{
    return m_pid;
}

}


